var angular = require('angular');
var coreRoutes = require('./routes/core.routes');
var navMenuService = require('./services/menu.service');
var registService = require('./services/regist.service');
var loginService = require('./services/login.service');
var homeService = require('./services/home.service');
var navbarController = require('./components/navbar/navbar.controller');
var navbarComponent = require('./components/navbar/navbar');

var homeController = require('./controller/home.controller');
var loginController = require('./controller/login.controller');
var noPassCtrl = require('./controller/noPass.controller');
var clientInterceptor = require('./interceptor/client.interceptor');
var banController = require('./controller/ban.controller');


var fileDirective = require('./directives/file.directives');
var registController = require('./controller/regist.controller');
const moduleName = 'core';

angular.module(moduleName, [])
    .config(coreRoutes)
    .config(['$httpProvider', function($httpProvider){
        $httpProvider.interceptors.push(clientInterceptor);
    }])
    .directive('fileModel',fileDirective)
    .factory('navMenuService', navMenuService)
    .factory('registService',registService)
    .factory('loginService',loginService)
    .factory('homeService',homeService)
    .component('navbar', navbarComponent)
    .controller('navbarController', navbarController)
    .controller('homeController', homeController)
    .controller('loginController', loginController)
    .controller('registController',registController)
    .controller('noPassCtrl', noPassCtrl)
    .controller('banController',banController)
    .run(run);

run.$inject = [
    '$location',
    '$rootScope',
    '$http'
];

function run($location, $rootScope, $http) {
    $rootScope.$on('$locationChangeStart', function (event, current, previous) {
        console.log(JSON.stringify(current));
        var flag = true;
        if (!flag) {
            $location.path('/error');
            return;
        }
        console.log("location change to" + JSON.stringify(current));
    });
}

module.exports = moduleName;